function onAddNewPartner(frmID, msgDiv, listtable)
{
	var newId = '';
	
	$(frmID).request(
		{
			asynchronous: false,
			parameters: $(frmID).serialize(true),
	  		onComplete: function(transport)
	  		{ 
			  	var response = transport.responseText || "";
		    	
		    	$(msgDiv).innerHTML = '';

		    	if(response != "")
		    	{
		    		obj = response.evalJSON();
		    		
		    		if(obj == null)
		    		{
		    			$(msgDiv).update('Something wrong! Reponsed string is: ' + response);
		    		}
		    		
			    	if(msgDiv != null)
				    	$(msgDiv).update(obj.message);
				    
				    
				    if(obj.ID >= 0)
					{	
						
					    if(listtable != null && $(listtable) != null)
					    {
							sClassName = 'newrow';
							str = '<tr id="partner-' + obj.ID + '" class="newrow">';
							str += '<th scope="row" style="text-align: center">' + obj.ID + '</th>';
							str += '<td>' + obj.partner_name + '</td>';
							str += '<td>' + '<img src="../includes/thumb.php?src='+obj.partner_image+'" alt="" border="0" />' + '</td>';
							str += '<td align="center">' + obj.partner_status + '</td>';
							str += '<td align="center">' + obj.partner_url + '</td>';
							str += '<td><a href="?mod=partnerman&sub1=editpartner&id=' + obj.ID + '" class="edit">Edit</td>';
							str +=	'	<td style="text-align: center"><a onclick="onDeletePartner(\'?mod=partnerman\', \'' + obj.ID  + '\', \'' + obj.partner_image  + '\')"'; 
							str +=	'			class="delete">Delete</td>';
							str += '</tr>';

							$(listtable).innerHTML += str;
							
							newId = 'partner-' + obj.ID;
					    }
		    		}
		    	}
	  		}
		});

	$(msgDiv).style.display = 'block';
	Fat.fade_element(msgDiv, null, 1500, null, null);
	if(newId != '')
	{
		Fat.fade_element(newId);
		$(frmID).reset();
	}
	//revent submit page
	return false;
}

function onDeletePartner(url, partnerId, partnerImage)
{
	var isOK = -1;
	
	if(!confirm('Are you sure you want to delete the partner with Id:' + partnerId))
	{
		return false;
	}
	
	new Ajax.Request(url, 
	{
	  method: 'post',
	  asynchronous: false,
	  parameters:'act=delpartner&id=' + partnerId + '&partner_image=' + partnerImage,
	  onSuccess: function(transport) 
  		{
			var response = transport.responseText.trim();
			
			//alert(response);
			
			obj = response.evalJSON();

    		if(obj == null)
    		{
    			$('ajaxResponse1').innerHTML = 'Something wrong! Reponsed string is: ' + response;
    		}
    		
    		isOK = obj.code;
		
    		$('ajaxResponse1').update(obj.message);
		}
	});

	$('ajaxResponse1').style.display = 'block';
	Fat.fade_element('ajaxResponse1', null, 1500, null, null);

	if(isOK == 0)
	{
		rowID = 'partner-' + partnerId;
		Fat.fade_element(rowID, null, 1000, "#f22", null);
		setTimeout("$(rowID).remove()", 1000);
		
	}				
}


function onEditPartner(frmID, msgDiv)
{
	var newId = '';
	var status = null;
	var ret = null;
	var message = null;
	$(frmID).request(
		{
			asynchronous: false,
			parameters: $(frmID).serialize(true),
	  		onComplete: function(transport)
	  		{ 
			  	var response = transport.responseText || "";
			  	var pos=response.indexOf('<!');
				content=response.substring(1,pos);
				//alert(content);
		    	$(msgDiv).innerHTML = '';
		    	if(content != "")
		    	{
		    		obj = content.evalJSON();
		    		if(obj == null)
		    		{
		    			$(msgDiv).update('Something wrong! Reponsed string is: ' + content);
		    		}
		    		
			    	if(msgDiv != null)
				    	$(msgDiv).update(obj.message);
					if(obj.ID==0)
					{
						ret =1;	
						message = obj.msg;
					}
					
		    	}
	  		}
		});
	if(ret==1)
	{
		document.location = '?mod=partnerman&message=' + message;
	}
	else
	{
	$(msgDiv).style.display = 'block';
	Fat.fade_element(msgDiv, null, 1500, null, null);
	//revent submit page
	}
	return false;
}